export default class {
	constructor() {
		// 获取当前时间的毫秒数
		this.timeNow = new Date().getTime();
	}
	formTime(time) {
		let date = new Date(time);
		let year = date.getFullYear();
		let month = date.getMonth() + 1;
		let day = date.getDate();
		let hour = date.getHours();
		// 分钟不够两位数就补0
		let minute = date.getMinutes().toString().padStart(2, "0");
		let second = date.getSeconds();

		let str = "";
		if (hour < 11) {
			str = "上午";
		} else if (hour > 13) {
			str = "下午";
		} else {
			str = "中午";
		};
		let week = ["星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"][date.getDay()];
		return `${year}年${month}月${day}日 ${week} ${str} ${hour} : ${minute}`;
	}
	// 获取聊天时间，相差300s内的消息不会显示时间
	chatTime(chatTime1, chatTime2) {
		chatTime1 = chatTime1.toString().length < 13 ? chatTime1 * 1000 : chatTime1;
		chatTime2 = chatTime2.toString().length < 13 ? chatTime2 * 1000 : chatTime2;
		if ((parseInt(chatTime1) - parseInt(chatTime2) / 1000) > 3000) return chatTime1;
	}
	// "2020-09-12"这种出生年月日的时间格式和当前的日期进行比较
	compareTime(times) {
		let date = new Date(this.timeNow);
		let year = date.getFullYear();
		let month = date.getMonth() + 1;
		let day = date.getDate();

		let timeArr = times.split("-");
		if (parseInt(timeArr[0]) > year) {
			return `年份不对`;
		} else if (parseInt(timeArr[1]) > month) {
			return `月份不对`;
		} else if (parseInt(timeArr[1]) == month && parseInt(timeArr[2]) > day) {
			return `日期不对`;
		};
		return true;
	}

};
